package com.zyj.action;


import java.util.UUID;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.zyj.util.ImageCrop;



public class SaveAction {
	
	private int x;
	private int y;
	private int w;
	private int h;
	private String imagename;
	private String smallimagename;
	

	public String execute(){
		System.out.println(x);
		System.out.println(y);
		System.out.println(w);
		System.out.println(h);
		System.out.println(imagename);
		
		ServletContext ctx = ServletActionContext.getServletContext();
		String path = ctx.getRealPath("/upload/");
		String srcpath = path + "/" + imagename;
		
		String type= srcpath.substring(srcpath.lastIndexOf(".")+1);
		
		smallimagename = UUID.randomUUID().toString() + "." + type;
		
		String subpath = path + "/" + smallimagename;
		
		ImageCrop.cut(srcpath,subpath,type, x, y, w, h);
		
		return "success";
	}


	public int getX() {
		return x;
	}



	public void setX(int x) {
		this.x = x;
	}



	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getW() {
		return w;
	}

	public void setW(int w) {
		this.w = w;
	}



	public int getH() {
		return h;
	}



	public void setH(int h) {
		this.h = h;
	}



	public String getImagename() {
		return imagename;
	}



	public void setImagename(String imagename) {
		this.imagename = imagename;
	}



	public String getSmallimagename() {
		return smallimagename;
	}



	public void setSmallimagename(String smallimagename) {
		this.smallimagename = smallimagename;
	}



	
}
